//
//  HYLBaseViewController.swift
//  iOSwechat
//
//  Created by apple on 16/2/27.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class HYLBaseViewController: UITableViewController {

    
    
    
//    var userLogin = true
    var isLogin = HYLUserAccountViewModel.sharedInstance.userLogin
    // 当用户没有登录,使用自定义的界面,如果用户登录了就走父类的流程
    override func loadView() {
        isLogin ? super.loadView(): setupRegisterView()
    }

    // MARK: - 访问视图懒加载
    private lazy var registerView:HYLRegisterView = HYLRegisterView()
    
    // MARK: - 设置访客视图
    private func setupRegisterView() {
//        registerView = HYLRegisterView()
//        view = registerView

        view = registerView
        
        // 判断当前控制器
        if self is HYLHomeViewController{
               registerView.startRotationAnimation()
        } else if self is HYLMessageViewController{
            registerView.setupRegisterInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if self is HYLDiscoverViewController {
            registerView.setupRegisterInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if self is HYLMeViewContrller {
            registerView.setupRegisterInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonClick")

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClick")

        
        registerView.registerViewDelegate = self
    }
    
}


extension HYLBaseViewController : HYLRegisterViewDelegate {
    func registerButtonClick(){
        let networkToll = HYLNetworkTool.sharedInstance
        print("注册界面:\(networkToll.oauthLoginUrl())")
    }
    
    func loginButtonClick() {

//        print("登录界面:\(networkToll.oauthLoginUrl())")
        
        // 跳转控制器
        let oauthVC = HYLOauthViewController()
        
       presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
       
    }
}
